package top.lyunz.fangkeji.tools;


import java.io.IOException;

import org.json.JSONObject;
import org.springframework.web.multipart.MultipartFile;

import net.coobird.thumbnailator.Thumbnails;
import top.lyunz.fangkeji.controller.web.web;

public class imgproc {
	public static String saveimg(MultipartFile file)
	{
		String ret = null;
		if(file == null)
			return ret;
		String originalFilename = file.getOriginalFilename();
		String prefix = originalFilename.substring(originalFilename.lastIndexOf("."));
		img img = new img();
		String timeString = System.currentTimeMillis() + "";
		String Img = timeString + prefix;
		String newImg = timeString + "-thumbnail" + prefix;
		img.uploadingImg(file, Img);
		ret = newImg;
		try {
			Thumbnails.of(web.imgurlpath + Img).scale(0.5f).outputQuality(0.5f).toFile(web.imgurlpath + newImg);
		} catch (IOException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
			ret = null;
		}
		delFile delFile = new delFile();
		delFile.del(web.imgurlpath, Img);
		
		return ret;
	}
	
	public static int detectface(String img)
	{
		baiduyun baiduyun = new baiduyun();
		Integer baiduyunAPI = baiduyun.baiduyunAPI(img);
		if(baiduyunAPI==1) {
			return 1;
		}
		else 
		{
			if(baiduyunAPI!=1) {
				return 2;
			}
		}

		return 0;
	}
	

}